package com.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;


import java.io.IOException;
import java.io.InputStream;

/**
 * Created by webrx on 2017/6/15.
 */
@Data
@AllArgsConstructor
public class MybatiesUtil {
    private SqlSessionFactory sf;
    private SqlSession session;

    public MybatiesUtil() throws IOException {
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        this.sf = new SqlSessionFactoryBuilder().build(inputStream);
        this.session = this.sf.openSession();

    }

}
